
package com.rx.mgt.dao;  

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.UserAlias;
import com.rx.mgt.po.UsersBo;

/** 
 * ClassName:UserAliasDao 
 * Function :
 * Reason   : 
 * Date     :Jan 31, 2017 9:21:11 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Repository
public class UserAliasDao extends ManagementHibernateDaoBase<UserAlias, Long>{
    @Transactional(readOnly=true)
    public List getAllUserAlias(UsersBo usersBo){
        String hql= " from UserAlias au where 1=1  ";
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            hql=hql +" and au.domain=:domain";
        }
        if(StringUtils.isNotBlank(usersBo.getName())){
            hql=hql +" and au.name=:name";
        }
        if(StringUtils.isNotBlank(usersBo.getAlias())){
            hql=hql +" and au.alias=:alias";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            query.setParameter("domain", usersBo.getDomain());
        }
        if(StringUtils.isNotBlank(usersBo.getName())){
            query.setParameter("name", usersBo.getName());
        }
        if(StringUtils.isNotBlank(usersBo.getAlias())){
            query.setParameter("alias", usersBo.getAlias());
        }
        return query.list();
    }

}
  